package com.open4cn.simulator.config.controller;

import com.open4cn.simulator.device.AnswerManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-05-20 13:23
 */
@RestController
@RequestMapping("manager/answer")
public class AnswerManagerController {

    /**
     * 查询设备应答器快照
     *
     * @param deviceId
     * @return
     */
    @GetMapping("/snapshot/{deviceId}")
    public Object getMultiSnapshot(@PathVariable(name = "deviceId") String deviceId) {
        return AnswerManager.getInstance().getMultiSnapshot(deviceId);
    }


    /**
     * 变更设备应答模式和应答值
     *
     * @param deviceId
     * @param scene
     * @param answerMode
     * @return
     */
    @GetMapping("/change/{deviceId}")
    public Object change(@PathVariable(name = "deviceId") String deviceId,
                         @RequestParam(name = "scene") String scene,
                         @RequestParam(name = "answerMode") String answerMode,
                         @RequestParam(name = "values", required = false) List<Object> values) {
        AnswerManager answerManager = AnswerManager.getInstance();
        answerManager.changeAnswerMode(deviceId, scene, answerMode, values);
        return answerManager.getSingleSnapshot(deviceId, scene);
    }

}
